package socket;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.zip.GZIPInputStream;

public class SocketInput {

	private InputStream input;

	public SocketInput(InputStream input) {
		super();
		this.input = input;
	}

	public int readInt() throws IOException {
		byte[] bytes = new byte[4];
		input.read(bytes);
		ByteBuffer buffer = ByteBuffer.allocate(4);
		buffer.put(bytes);
		return buffer.getInt();
	}

	public String readString() throws IOException {
		return new String(read());
	}

	public byte[] read() throws IOException {
		byte[] buffer = new byte[readInt()];
		input.read(buffer);
		return buffer;
	}
}
